package com.share.tool.m2d.kundb.canal;

import com.share.common.utils.FileUtil;
import com.share.tool.m2d.kundb.tablestructure.DbMainV2;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.List;

public class SyncMain {

    public static void main(String[] args) {
        String output = "E:\\share\\syq\\qianyi\\canal\\";

        //读取模板
        String canalYmlPath = DbMainV2.class.getClassLoader().getResource("kundb\\canal.yml").getPath();
        String str = FileUtil.read(canalYmlPath);

        String canalTxtPath = DbMainV2.class.getClassLoader().getResource("kundb\\canal.txt").getPath();
        List<String> list = FileUtil.readByLine(canalTxtPath);
        StringBuffer sb = new StringBuffer();
        for (String line : list) {
            line = line.trim();
            if (StringUtils.isBlank(line)) {
                continue;
            }

            String[] split = line.split(",");
            String table = split[0];
            String id = split[1];
            String condition = split[2];

            String s = str.replaceAll("#table", table).replaceAll("#id", id).replaceAll("#condition", condition);


            //输出到文件
            String filePath = output + "channel_" + table + ".yml";
            FileUtil.write(new File(filePath), s);
        }

        System.out.println(sb.toString());
    }
}
